# author = '李天宝'
# write in '2020/8/5 0005 20:21'

from rest_framework.views import APIView
from rest_framework.response import Response
from common.moexception import NoDataException
from LoginSign.models import User,address

class DelAddress(APIView):
    """
    post
    把id号或者详细地址增加出来 两个写其中一个过来就可以了
    id 地址ID号
    region_name 详细地址
    """
    def post(self,request):

        if 'id' and 'region_name' not in request.data:
            raise NoDataException("没有把id或者region_name传送进来")

        if 'id' in request.data:
            id=request.data['id']
            addr=address.objects.filter(id=id)
        else:
            region_name=request.data['region_name']
            addr=address.objects.filter(region_name=region_name)
        addr.default_flag=True
        addr.save()

        return Response({
            'code':200,
            'detail':'删除成功'
        })
